//
//  YMSMemberManager.m
//  yameishe3
//
//  Created by pro on 2017/3/2.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "YMSMemberManager.h"
#import "DataFetch.h"
@implementation YMSMemberManager

singleton_implementation(YMSMemberManager)

-(void)getTokenWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@get_token",BasicUrl];
    [DataFetch getWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary*)resultObj;
        YMSMember *member = [YMSMember loginMember];
        if (!member) {
            member = [[YMSMember alloc]init];
        }
        member.token = dic[@"data"];
        [YMSMember setLoginMember:member];
        [YMSMember saveLoginMember];
        successBlock(dic);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];


}

-(void)getVerificationCodeWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@send/sms",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
    
    } Cache:^(id cacheObj) {
    
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
}

-(void)getEmailCodeWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@password/email",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
}

-(void)MemberRegisterWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@user/register",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
}

-(void)MemberLoginWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@user/Api_postLogin",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        successBlock(dic);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];

}

-(void)MemberLogoutWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@user/_logout",BasicUrl];
    [DataFetch getWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        successBlock(dic);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
    
}

-(void)MemberUpdateInfoWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@user/info",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        successBlock(dic);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];

}

//-(void)MemberChangePhoneNumWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
//{
//    NSString *link = [NSString stringWithFormat:@"%@user/Api_postLogin",BasicUrl];
//    [DataFetch getWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
//        
//    } Cache:^(id cacheObj) {
//        
//    }];
//}

-(void)MemberBasicInfoWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@user/_user_data",BasicUrl];
    [DataFetch getWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        NSString *sta = dic[@"sta"];
        NSLog(@"%@",sta);
        NSDictionary *dicn = dic[@"data"];
        
        successBlock(dicn);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
}

-(void)MemberGetQuestionWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@security/_data_con",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        successBlock(dic);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];

}
-(void)MemberSetQuestionWithDic:(NSMutableDictionary*)dic successBlock:(SuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@user/safety_set",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        successBlock(dic);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
    
}

-(void)MemberGetMyQuestionWithDic:(NSMutableDictionary*)dic successBlock:(ArraySuccessBlock)successBlock failureBlock:(FailureBlock)failureBlock
{
    NSString *link = [NSString stringWithFormat:@"%@question",BasicUrl];
    [DataFetch postWithApi:link Dic:dic Completion:^(NSURLSessionDataTask *operation, id resultObj, NSString *link) {
        NSDictionary *dic = (NSDictionary *)resultObj;
        NSArray *array = dic[@"data"];
        successBlock(array);
    } Cache:^(id cacheObj) {
        
    } Fail:^(NSString *reason) {
        failureBlock(reason);
    }];
}

@end
